package patterns.behavior.observer;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public abstract class Subject {

    protected List<Observer> list = new ArrayList<>();

    public void register(Observer observer){
        list.add(observer);
    }

    public void delete(Observer observer){
        Iterator<Observer> iterator = list.iterator();
        while (iterator.hasNext()){
            if(iterator.next().equals(observer)){
                iterator.remove();
                break;
            }
        }
    }

    public abstract void notifyObserver(); //通知观察者方法

}
